package com.chenyaowei.product.service.impl;

import java.util.List;

import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.product.domain.CywProductBrand;
import com.chenyaowei.product.domain.CywProductCategory;
import com.chenyaowei.product.service.ICywProductBrandService;
import com.chenyaowei.product.service.ICywProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.chenyaowei.product.mapper.CywBrandCategoryRelationMapper;
import com.chenyaowei.product.domain.CywBrandCategoryRelation;
import com.chenyaowei.product.service.ICywBrandCategoryRelationService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 品牌分类关联Service业务层处理
 *
 * @author 陈耀威
 * @date 2023-11-22
 */
@Service
public class CywBrandCategoryRelationServiceImpl implements ICywBrandCategoryRelationService
{
    @Autowired
    private CywBrandCategoryRelationMapper cywBrandCategoryRelationMapper;

    @Autowired
    private ICywProductBrandService brandService;

    @Autowired
    private ICywProductCategoryService categoryService;

    /**
     * 查询品牌分类关联
     *
     * @param id 品牌分类关联主键
     * @return 品牌分类关联
     */
    @Override
    public CywBrandCategoryRelation selectCywBrandCategoryRelationById(Long id)
    {
        return cywBrandCategoryRelationMapper.selectCywBrandCategoryRelationById(id);
    }

    /**
     * 查询品牌分类关联列表
     *
     * @param cywBrandCategoryRelation 品牌分类关联
     * @return 品牌分类关联
     */
    @Override
    public List<CywBrandCategoryRelation> selectCywBrandCategoryRelationList(CywBrandCategoryRelation cywBrandCategoryRelation)
    {
        return cywBrandCategoryRelationMapper.selectCywBrandCategoryRelationList(cywBrandCategoryRelation);
    }

    /**
     * 新增品牌分类关联
     *
     * @param cywBrandCategoryRelation 品牌分类关联
     * @return 结果
     */
    @Override
    public int insertCywBrandCategoryRelation(CywBrandCategoryRelation cywBrandCategoryRelation)
    {
        return cywBrandCategoryRelationMapper.insertCywBrandCategoryRelation(cywBrandCategoryRelation);
    }

    /**
     * 修改品牌分类关联
     *
     * @param cywBrandCategoryRelation 品牌分类关联
     * @return 结果
     */
    @Override
    public int updateCywBrandCategoryRelation(CywBrandCategoryRelation cywBrandCategoryRelation)
    {
        return cywBrandCategoryRelationMapper.updateCywBrandCategoryRelation(cywBrandCategoryRelation);
    }

    /**
     * 批量删除品牌分类关联
     *
     * @param ids 需要删除的品牌分类关联主键
     * @return 结果
     */
    @Override
    public int deleteCywBrandCategoryRelationByIds(Long[] ids)
    {
        return cywBrandCategoryRelationMapper.deleteCywBrandCategoryRelationByIds(ids);
    }

    /**
     * 删除品牌分类关联信息
     *
     * @param id 品牌分类关联主键
     * @return 结果
     */
    @Override
    public int deleteCywBrandCategoryRelationById(Long id)
    {
        return cywBrandCategoryRelationMapper.deleteCywBrandCategoryRelationById(id);
    }

    @Override
    public int saveCywBrandCategoryRelation(Long brandId, Long catelogId) {
        CywProductBrand brand = brandService.selectCywProductBrandByBrandId(brandId);
        CywProductCategory category = categoryService.selectCywProductCategoryByCatId(catelogId);
        CywBrandCategoryRelation entity = new CywBrandCategoryRelation();
        entity.setBrandId(brandId);
        entity.setCatelogId(catelogId);
        entity.setBrandName(brand.getName());
        entity.setCatelogName(category.getName());
        return cywBrandCategoryRelationMapper.insertCywBrandCategoryRelation(entity);
    }

    @Override
    public List<CywBrandCategoryRelation> selectBrandListByCatelogId(Long catelogId) {
        return cywBrandCategoryRelationMapper.selectBrandListByCatelogId(catelogId);
    }

    @Override
    public List<CywBrandCategoryRelation> selectListByCatelogId(Long catelogId) {
        return cywBrandCategoryRelationMapper.selectListByCatelogId(catelogId);
    }

    @Override
    public List<CywBrandCategoryRelation> selectListByCatelogIds(List<Long> catelogIds) {
        return cywBrandCategoryRelationMapper.selectListByCatelogIds(catelogIds);
    }
}
